package cn.tedu.csmall520.cart.webapi.service.impl;

import cn.tedu.csmall520.cart.serivce.ICartService;
import cn.tedu.csmall520.cart.webapi.mapper.CartMapper;
import cn.tedu.csmall520.commons.pojo.cart.dto.CartAddDTO;
import cn.tedu.csmall520.commons.pojo.cart.entity.Cart;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@DubboService
public class CartSerivceImpl implements ICartService {

    @Autowired
    private CartMapper cartMapper;

    @Override
    public void addNew(CartAddDTO cartAddDTO) {
        log.debug("开始处理新增购物车商品的业务，接收到的参数是：{}",cartAddDTO);
        Cart cart = new Cart();
        BeanUtils.copyProperties(cartAddDTO,cart);
        int i = cartMapper.addNew(cart);
        if (i != 1) {
            log.debug("新增失败！！！");
        }
    }

    @Override
    public void delete(String userId, String commodityCode) {
        log.debug("开始处理删除购物车商品的业务");
        int delete = cartMapper.delete(userId, commodityCode);
        if (delete != 1) {
            log.debug("删除失败！！！");
        }
    }
}
